<?php
$url = url('admin','users-manager');
if(!isset($_GET['id'])){
    header("location: {$url}");
    exit(0);
} 
$user = $Bus->User->getItemById($_GET['id']);
if(!$user){
    header("location: {$url}");
    exit(0);
}

include 'component/header.php';
include 'component/slidebar.php'; 
?>
<!-- BEGIN CONTENT -->
<script type="text/javascript">
$(function(){
    /*Khởi tạo datepicker*/
    var curent = new Date();
    var year = curent.getFullYear();
    $("#datepicker").datepicker({
        onSelect: function(dateText, inst){
            $("#txtBirthday").val(dateText);
            $(this).hide();},
        dateFormat: 'dd-mm-yy',
        changeMonth: true,
        changeYear: true,
        yearRange: '1900:'+ year
    });
    
    /*Hiện ẩn datepicker*/
    $("#datepicker").css('display','none')
                    .css('position','absolute')
                    .css('left','270px')
                    .css('top','400px');
                    
    $("#b_calendar").click(function(){
        $("#datepicker").toggle('slow');
    });
});
</script>
<div id="content">
    <div class="box-out">
    	<div class="box-in">
    		<div class="box-head"><h1>Sửa thông tin người dùng</h1></div>
    		<div class="box-content">
                <?php if(isset($error)) {?>
                <div class="notification error">
    				<div class="messages"><?php echo $error; ?><div class="close"><img src="css/images/icon/close.png" alt="close" /></div></div>
    			</div><!-- end div .notification error -->
                <?php }?>
                
                <?php if(isset($message)) {?>
                <div class="notification success">
    				<div class="messages">
                        <?php echo $message;?> 
                        <div class="close"><img src="css/images/icon/close.png" alt="close" /></div>
                    </div>
    			</div><!-- end div .notification success -->
                <?php }?>
    			<div class="form">
    				<form action="<?php echo url('admin','users-edit',array('id'=>$user->idusers));?>" method="post" >
    					<fieldset>
    						<label for="small_field">Username</label>
    						<input type="text" class="text small" name="txtUserName" value="<?php echo $user->users_name;?>" />
                            <label for="small_field">Password</label>
    						<input type="password" class="text small" name="txtUserPass" value="<?php echo $user->users_pass;  ?>" />
                            <label for="medium_field">Họ và Tên</label>
                            <input id="medium_field" class="text medium" type="text" name="txtUserFullname" value="<?php echo $user->users_fullname;  ?>" />
                            <label for="medium_field">Địa chỉ</label>
                            <input id="medium_field" class="text medium" type="text" name="txtUserAddress" value="<?php echo $user->users_address;  ?>" />
                            <label for="small_field">Điện Thoại</label>
    						<input type="text" class="text small" name="txtUserPhone" value="<?php echo $user->users_phone;  ?>" />
                            <label for="small_field">Ngày sinh <span style="font-weight: normal; font-style: italic;">(dd-mm-yyyy)</span></label>
    						<input type="text" class="text small" id="txtBirthday"  name="txtUserBirthday" value="<?php echo date("d-m-Y",strtotime($user->users_birthday));?>" />
                            <img src="css/images/icon/b_calendar.png" id="b_calendar" />
                            <div id="datepicker"></div>
                            <label for="select_field">Thuộc nhóm</label>
                            <?php $Dtos = $Bus->Group->getAllData();?>
                            <select class="text" name="selGroup">
                                <?php foreach($Dtos as $dto) { 
                                $select = ($user->groups_idgroups == $dto->idgroups)?"selected='selected'":"";?>
                                <option <?php echo $select;?> value="<?php echo $dto->idgroups;?>"><?php echo $dto->groups_name;?></option>
                                <?php }?>
    						</select>
                            <label for="select_field">Trạng thái</label>
                            <?php $Dtos = $Bus->Status_User->getAllData();?>
                            <select class="text" name="selStatusUser">
                                <?php foreach($Dtos as $dto) { 
                                $select = ($user->userstatus_iduserstatus == $dto->iduserstatus)?"selected='selected'":"";?>
                                <option <?php echo $select;?> value="<?php echo $dto->iduserstatus;?>"><?php echo $dto->userstatus_name;?></option>
                                <?php }?>
    						</select>
    						<hr />
    						<input type="submit" value="Sửa thông tin" class="submit" name="btSubmit" />
                            <a class="submit" href="<?php echo url('admin','users-manager');?>">Về trang quản lý</a>
    					</fieldset>
    				</form>
    			</div><!-- end div .form -->
    		</div><!-- end div .box-content -->
    	</div><!-- end div .box-in -->
</div><!-- end div #content -->
<!-- END CONTENT -->

<?php
include 'component/footer.php'; 
?>